﻿Imports clases

Public Class frm
    Public miTest As Test

    Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim temas As New List(Of String)
        temas = gestion.NombresFicheros
        For i As Integer = 0 To temas.Count - 1
            cboTemas.Items.Add(temas(i))
        Next
    End Sub


    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        Dim nuevo As String
        nuevo = InputBox("Indica el nuevo tema")
        Dim test As New Test(nuevo)
        cboTemas.Items.Clear()
        Dim temas As New List(Of String)
        temas = gestion.NombresFicheros
        For i As Integer = 0 To temas.Count - 1
            cboTemas.Items.Add(temas(i))
        Next


    End Sub

    Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrar.Click
        Dim boton As DialogResult
        boton = MessageBox.Show("¿Desea borrar?" & cboTemas.SelectedItem, "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If boton = Windows.Forms.DialogResult.Yes Then
            gestion.EliminarFichero(cboTemas.SelectedItem)
        End If
        cboTemas.Items.Clear()
        Dim temas As New List(Of String)
        temas = gestion.NombresFicheros
        For i As Integer = 0 To temas.Count - 1
            cboTemas.Items.Add(temas(i))
        Next

    End Sub


    Private Sub cboTemas_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboTemas.SelectedIndexChanged
        grpBotones.Visible = True
        miTest = New Test(cboTemas.SelectedItem)


    End Sub

    Private Sub btnResponder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResponder.Click
        Dim controls1() As Control = Me.Controls.Find("txt", False)
        For a As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls1(a))
        Next
        Dim controls2() As Control = Me.Controls.Find("chk", False)
        For b As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls2(b))
        Next
        Dim controls3() As Control = Me.Controls.Find("btnAceptar", False)
        For c As Integer = 0 To controls3.Length - 1
            Me.Controls.Remove(controls3(c))
        Next
        Dim controls4() As Control = Me.Controls.Find("btnCancelar", False)
        For d As Integer = 0 To controls4.Length - 1
            Me.Controls.Remove(controls4(d))
        Next
        If miTest.Preguntas.Count = 0 Then
            MessageBox.Show("Imposible, no hay preguntas", "Hacer Test")
            Exit Sub
        End If
        Dim txt As TextBox
        Dim check As CheckBox

        Dim sumaY As Integer = 110
        For i As Integer = 0 To miTest.Preguntas.Count - 1
            txt = New TextBox
            check = New CheckBox
            txt.Visible = True
            txt.Enabled = True
            txt.Text = miTest.Preguntas(i).Enunciado
            check.Checked = False
            check.Enabled = True
            check.Visible = True
            txt.Name = "txt"
            check.Name = "chk"
            check.Text = "Verdadera"
            txt.Size = New Size(312, 23)
            txt.Location = New Point(50, sumaY)
            check.Location = New Point(70 + txt.Width, sumaY)
            Me.Controls.Add(check)
            Me.Controls.Add(txt)
            sumaY = sumaY + 40


        Next
        Dim aceptar As New Button
        aceptar.Text = "Aceptar"
        aceptar.Size = New Size(75, 23)
        aceptar.Location = New Point(50, sumaY + 60)
        aceptar.Enabled = True
        aceptar.Visible = True
        aceptar.Name = "btnAceptar"
        Dim cancelar As New Button
        cancelar.Text = "Cancelar"
        cancelar.Size = New Size(75, 23)
        cancelar.Location = New Point(70 + aceptar.Width, sumaY + 60)
        cancelar.Enabled = True
        cancelar.Visible = True
        cancelar.Name = "btnCancelar"
        Me.Controls.Add(aceptar)
        Me.Controls.Add(cancelar)
        AddHandler aceptar.Click, AddressOf btn_Click
        AddHandler cancelar.Click, AddressOf btncan_click



    End Sub

    Private Sub btnAñadir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAñadir.Click
        frmAñadir.ShowDialog()

    End Sub

    Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModificar.Click
        frmModificar.ShowDialog()
        Dim controls1() As Control = Me.Controls.Find("txt", False)
        For a As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls1(a))
        Next
        Dim controls2() As Control = Me.Controls.Find("chk", False)
        For b As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls2(b))
        Next
        Dim controls3() As Control = Me.Controls.Find("btnAceptar", False)
        For c As Integer = 0 To controls3.Length - 1
            Me.Controls.Remove(controls3(c))
        Next
        Dim controls4() As Control = Me.Controls.Find("btnCancelar", False)
        For d As Integer = 0 To controls4.Length - 1
            Me.Controls.Remove(controls4(d))
        Next
        If miTest.Preguntas.Count = 0 Then
            MessageBox.Show("Imposible, no hay preguntas", "Hacer Test")
            Exit Sub
        End If

    End Sub

   
    Private Sub btnBorrarPreguntas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrarPreguntas.Click
        frmBorrar.ShowDialog()
        Dim controls1() As Control = Me.Controls.Find("txt", False)
        For a As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls1(a))
        Next
        Dim controls2() As Control = Me.Controls.Find("chk", False)
        For b As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls2(b))
        Next
        Dim controls3() As Control = Me.Controls.Find("btnAceptar", False)
        For c As Integer = 0 To controls3.Length - 1
            Me.Controls.Remove(controls3(c))
        Next
        Dim controls4() As Control = Me.Controls.Find("btnCancelar", False)
        For d As Integer = 0 To controls4.Length - 1
            Me.Controls.Remove(controls4(d))
        Next


    End Sub


    
  
    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Close()

    End Sub
    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.ErrorProvider1.Clear()
        Dim total As Integer
        Dim controls() As Control = Me.Controls.Find("chk", False)
        Dim chk As New CheckBox
        For i As Integer = 0 To controls.Length - 1
            chk = controls(i)
            Dim sino As Boolean = False
            If chk.Checked = True Then
                sino = True
            End If
            If miTest.Preguntas(i).Respuesta = sino Then
                total = total + 1
            Else
                Me.ErrorProvider1.SetError(chk, "Respuesta incorrecta")
            End If

        Next
        MessageBox.Show("Has acertado " & total & " preguntas")

    End Sub
    Private Sub btncan_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim controls1() As Control = Me.Controls.Find("txt", False)
        For a As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls1(a))
        Next
        Dim controls2() As Control = Me.Controls.Find("chk", False)
        For b As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls2(b))
        Next
        Dim controls3() As Control = Me.Controls.Find("btnAceptar", False)
        For c As Integer = 0 To controls3.Length - 1
            Me.Controls.Remove(controls3(c))
        Next
        Dim controls4() As Control = Me.Controls.Find("btnCancelar", False)
        For d As Integer = 0 To controls4.Length - 1
            Me.Controls.Remove(controls4(d))
        Next
        Dim txt As TextBox
        Dim check As CheckBox

        Dim sumaY As Integer = 110
        For i As Integer = 0 To miTest.Preguntas.Count - 1
            txt = New TextBox
            check = New CheckBox
            txt.Visible = True
            txt.Enabled = True
            txt.Text = miTest.Preguntas(i).Enunciado
            check.Checked = False
            check.Enabled = True
            check.Visible = True
            txt.Name = "txt"
            check.Name = "chk"
            check.Text = "Verdadera"
            txt.Size = New Size(312, 23)
            txt.Location = New Point(50, sumaY)
            check.Location = New Point(70 + txt.Width, sumaY)
            Me.Controls.Add(check)
            Me.Controls.Add(txt)
            sumaY = sumaY + 40


        Next
        Dim aceptar As New Button
        aceptar.Text = "Aceptar"
        aceptar.Size = New Size(75, 23)
        aceptar.Location = New Point(50, sumaY + 60)
        aceptar.Enabled = True
        aceptar.Visible = True
        aceptar.Name = "btnAceptar"
        Dim cancelar As New Button
        cancelar.Text = "Cancelar"
        cancelar.Size = New Size(75, 23)
        cancelar.Location = New Point(70 + aceptar.Width, sumaY + 60)
        cancelar.Enabled = True
        cancelar.Visible = True
        cancelar.Name = "btnCancelar"
        Me.Controls.Add(aceptar)
        Me.Controls.Add(cancelar)
        AddHandler aceptar.Click, AddressOf btn_Click
        AddHandler cancelar.Click, AddressOf btncan_click
    End Sub




    Private Sub btnBorrarTodas_Click_1(sender As System.Object, e As System.EventArgs) Handles btnBorrarTodas.Click
        miTest.BorrarTodas()
        Dim controls1() As Control = Me.Controls.Find("txt", False)
        For a As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls1(a))
        Next
        Dim controls2() As Control = Me.Controls.Find("chk", False)
        For b As Integer = 0 To controls1.Length - 1
            Me.Controls.Remove(controls2(b))
        Next
        Dim controls3() As Control = Me.Controls.Find("btnAceptar", False)
        For c As Integer = 0 To controls3.Length - 1
            Me.Controls.Remove(controls3(c))
        Next
        Dim controls4() As Control = Me.Controls.Find("btnCancelar", False)
        For d As Integer = 0 To controls4.Length - 1
            Me.Controls.Remove(controls4(d))
        Next
        

    End Sub
End Class
